package com.you.member.dal.dao;

import java.util.HashMap;
import java.util.Map;

import com.you.common.ibatis.AbstractDAO;
import com.you.common.ibatis.data.DataList;
import com.you.common.ibatis.param.QueryParam;
import com.you.member.dal.dao.dataobject.FollowDO;


public class FollowDAO extends AbstractDAO{

    public Long create(FollowDO followDO){
        return (Long) super.getSqlMapClientTemplate().insert("MS-INSERT-FOLLOW",followDO);
    }
    
    public DataList queryFans(int pageNo,int pageSize,Long masterMemberId){
        QueryParam<String, Long>  queryParam = new QueryParam<String, Long>();
        queryParam.setPageNo(pageNo);
        queryParam.setPageSize(pageSize);
        queryParam.put("masterMemberId", masterMemberId);
        
        return super.getSqlMapClientTemplate().pagedQuery(queryParam, "MS-SELECT-FANS-MEMBER");
    }
    
    public Long countFans(Long followMemberId){
        return (Long) super.getSqlMapClientTemplate().queryForObject( "MS-COUNT-FANS-MEMBER",followMemberId);
    }
    public DataList queryFollow(int pageNo,int pageSize,Long fansMemberId){
        
        QueryParam  queryParam = new QueryParam<String, Long>();
        queryParam.setPageNo(pageNo);
        queryParam.setPageSize(pageSize);
        queryParam.put("fansMemberId", fansMemberId);
        
        return super.getSqlMapClientTemplate().pagedQuery(queryParam, "MS-SELECT-FOLLOW-MEMBER");
    }
    
    public Long countFollow(Long fansMemberId){
        return (Long) super.getSqlMapClientTemplate().queryForObject( "MS-COUNT-FOLLOW-MEMBER",fansMemberId);
    }
    
    public FollowDO findByMemberId(Long masterMemberId,Long fansMemberId){
        Map map = new HashMap<String, Long>();
        map.put("masterMemberId", masterMemberId);
        map.put("fansMemberId", fansMemberId);
        return (FollowDO) super.getSqlMapClientTemplate().queryForObject( "MS-SELECT-FOLLOW-BY-MEMBER-ID",map);
    }
}
